package com.example.ridingxu.penpaldemo;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.text.TextUtils;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by ridingxu on 2017/11/2.
 */

public class StartActivity extends Activity {
    boolean First = false;
    private static final int GO_HOME = 1000;
    private  static final int GO_GUIDE = 1001;
    //延迟3秒进入主页面
    private static final long SPLASH_DELAY_MILLIS =3000;

    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case GO_HOME:
                    goHome();
                    break;
                case GO_GUIDE:
                    goGuide();
                    break;
            }
            super.handleMessage(msg);
        }
    };

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start);
        init();

    }

    private void init() {
        //取得相应的值，如果没有该值，说明还未写入，用ture作为默认值
//        //判断程序第几次运行，如果是第一次运行则跳转到引导界面，否则跳转到主界面
//        SharedPreferences share = getSharedPreferences("First",MODE_PRIVATE);
//        String s = share.getString("FirstEntrance",null);
//        if (First || !TextUtils.isEmpty(s)){
//            mHandler.sendEmptyMessageDelayed(GO_HOME,SPLASH_DELAY_MILLIS);
//        }else {
//            mHandler.sendEmptyMessageDelayed(GO_GUIDE,SPLASH_DELAY_MILLIS);
//        };
        mHandler.sendEmptyMessageDelayed(GO_HOME,SPLASH_DELAY_MILLIS);
    }

    private void goGuide() {

    }


    private void goHome() {
        Intent intent = new Intent(StartActivity.this,LoginActivity.class);
        StartActivity.this.startActivity(intent);
        StartActivity.this.finish();
    }
}
